package com.fzj.example.socket.tcp.nonblock.bio;

import java.io.*;
import java.util.concurrent.TimeUnit;

/**
 * ClassName: ReceiveDataHandler
 * date: 2019/11/18 11:24
 * Description: TODO
 *
 * @author fanzj@bonree.com
 * @since JDK 1.8
 */
public class ReceiveDataHandler implements Runnable {

    private DataInputStream dataInputStream;

    ReceiveDataHandler(InputStream in){
        this.dataInputStream=new DataInputStream(in);
    }

    @Override
    public void run() {
         try{
             while (true){
                 TimeUnit.SECONDS.sleep(1);
                 System.out.println(this.dataInputStream.readUTF());
             }
         }catch (Exception e){
             try {
                 this.dataInputStream.close();
             } catch (IOException e1) {
                 e1.printStackTrace();
             }
             e.printStackTrace();
         }
    }
}
